﻿using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
///TimeUtil 的摘要说明
/// </summary>
public class TimeUtil
{
	public TimeUtil()
	{
		
	}

    /// <summary>
    /// 转换为自1970-1-1以来经过的毫秒数（用于和AS通讯）
    /// </summary>
    /// <param name="time">UTC日期实例</param>
    /// <returns></returns>
    public static long ToMillisecond(DateTime time)
    {
        return Convert.ToInt64((time - new DateTime(1970, 1, 1)).TotalMilliseconds);
    }

    /// <summary>
    /// 把自1970-1-1以来经过的毫秒数转换为时间
    /// </summary>
    /// <param name="millisecond"></param>
    /// <returns>UTC时间</returns>
    public static DateTime ToDateTime(long millisecond)
    {
        return new DateTime(1970, 1, 1).Add(new TimeSpan(millisecond * 1000 * 10));
    }
}